package com.ruoyi.storeroomuse.aspect;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.storeroomuse.service.IStoreroomUseService;
import com.ruoyi.storeroomuse.vo.StoreUseVO;
import com.ruoyi.system.domain.Storeroom;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class StoreUpdateAspect {

    @Autowired
    IStoreroomUseService storeroomUseService;

    @Pointcut("execution(public * com.ruoyi.system.service.IStoreroomService.update*(..))")
    public void myMethod(){
        //代理方法
    }
    @After("myMethod()")
    public void afterMethod(JoinPoint joinPoint){
        Object[] args = joinPoint.getArgs();
        for (Object every : args) {
            StoreUseVO storeUseVO = new StoreUseVO();
            if (every instanceof Storeroom){
                Storeroom eve=(Storeroom) every;
                storeUseVO.setStoreroomId(eve.getStoreroomId());
                SysUser sysUser = ShiroUtils.getSysUser();
                storeUseVO.setFounder(sysUser.getUserId());
                storeUseVO.setOperationName(2L);
                storeroomUseService.insertStoreroomUse(storeUseVO);
            }
        }
    }
}
